var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempFilePaths:'',
    areaText:'',
    inpText:''
  },

  // 上传图片
  chooseimage:function(){
    var _this=this;

    wx.chooseImage({
      count:1,
      sizeType:['original','compressed'],
      sourceType:['album','camera'],
      success:function(res){
        console.log(res)
        _this.setData({
          tempFilePaths:res.tempFilePaths
        })
        console.log(_this.data.tempFilePaths[0]);
        //base64编码存储
        wx.getFileSystemManager().readFile({
          filePath:_this.data.tempFilePaths[0],//图片本地路径
          encoding:"base64",
          success:res=>{
            _this.setData({
              tempFilePaths:'data:image/jpg;base64,'+res.data
            })
          }
        })
        
      }
    })
  },

  // 反馈标题
  inpIn:function(e){
    var that = this;
    that.setData({
      inpText:e.detail.value
    })
  },


  // 反馈内容
  areaIn:function(e){
    var that = this;
    that.setData({
      areaText:e.detail.value
    })
  },
  
  // 反馈按钮
  addproblem:function(){
    var _this = this;
    var problem={
      problem_tag:this.data.inpText,
      problem_content:this.data.areaText,
      problem_image_src:this.data.tempFilePaths,
      problem_user_id:wx.getStorageSync('user_id')
    };
    console.log(problem)
    wx.request({
      url: 'https://api.yidan.work:2004/problem',
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data:problem,
      method: 'POST',
      success:(res)=>{
        console.log("上传成功");
        
      }
    })
    _this.setData({
      tempFilePaths:'',
      areaText:'',
      inpText:''
    })
    wx.showToast({
      title: '提交成功',
      duration:2000
    })
    getCurrentPages()[getCurrentPages().length - 1].onLoad()
  },
//点击问题反馈列表
  problemList:function(){
    var problem={
      problem_tag:this.data.inpText,
      problem_content:this.data.areaText,
      problem_image_src:this.data.tempFilePaths,
      problem_user_id:wx.getStorageSync('user_id')
    };
    //console.log(problem)
    wx.navigateTo({
      url: '/pages/problemList/problemList?',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})